// packageH/schoolCompany/schoolCompanyReceive/schoolCompanyReceive.js
var app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    profitShow: false,
    diyform: {
      form_id: "",
      diyform_data_id: "",
      pre_id: "",
    },
    networkLoading: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getData();
  },

  gotoSchoolCompanyNum() {
    wx.navigateTo({
      url: "/packageH/schoolCompany/schoolCompanyNum/schoolCompanyNum",
    });
  },

  traCheckedData(e) {
    let diyform_data_id = e.detail.diyform_data_id;
    console.log(e);
    if (diyform_data_id) {
      this.setProfitShow();
      this.sendBtn(diyform_data_id);
    }
  },

  sendBtn(diyform_data_id) {
    let json = {
      form_data_id: diyform_data_id,
      form_id: this.data.diyform.form_id,
    };
    let urlStr = app.getNetAddresss("plugin.school-company.api.dividend.save-form-data");
    app._getNetWork({
      url: urlStr,
      data: json,
      success: (resdata) => {
        var res = resdata.data;
        if (res.result == 1) {
          this.setData({
            "userInfo.income_amount": 0,
          });
        }
      },
    });
  },

  setProfitShow() {
    this.setData({
      profitShow: !this.data.profitShow,
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  getData() {
    let urlStr = app.getNetAddresss("plugin.school-company.api.dividend.income");
    app._postNetWork({
      url: urlStr,
      success: (resdata) => {
        var res = resdata.data;
        if (res.result != 1) return app.tips(res.msg);
        let form = res.data.form;
        this.setData({
          userInfo: res.data,
          "diyform.form_id": form.id,
          networkLoading: true,
        });
      },
    });
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
});
